﻿@{
    Layout = "~/Views/Shared/_Form.cshtml";
}
@model Raffles.OA.Data.Role

@using Raffles.OA.Utility
@using Raffles.OA.Data
<form class="form-horizontal m" role="form">
    <div class="form-group">
        <label class="col-sm-3 control-label">角色编码<font class="red">*</font></label>
        <div class="col-sm-9">
            @Html.TextBoxFor(model => model.Code, new { @class = "form-control required", @placeholder = "请输入角色编码" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">角色名称<font class="red">*</font></label>
        <div class="col-sm-9">
            @Html.TextBoxFor(model => model.Name, new { @class = "form-control required", @placeholder = "请输入角色名称" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">数据范围<font class="red">*</font></label>
        <div class="col-sm-9">
            <select id="dataScope" col="DataScope" name="DataScope" class="form-control required">
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">显示顺序<font class="red">*</font></label>
        <div class="col-sm-9">
            @Html.TextBoxFor(model => model.DisplayOrder, new { @class = "form-control required", @type = "number", @min = "0", @placeholder = "请输入显示顺序" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">角色描述</label>
        <div class="col-sm-9">
            @Html.TextAreaFor(model => model.Description, new { @class = "form-control", @placeholder = "请输入角色描述" })
        </div>
    </div>
</form>
<script>
    var id = frame.request("id");
    $(function () {
        $("#dataScope").frameSelect({
            data: frame.getJson(@Html.Raw(typeof(DataScopeEnum).EnumToDictionaryString())),
            default: @((int)DataScopeEnum.SELF),
            onChange: function (event) {
                $(this).valid();
            }
        });
        if (!!id) {
            $("#dataScope").frameSelect("setValue", @Model.DataScope);
        }
    })
    function saveForm() {
        if ($('form').validate().form()) {
            frame.ajax({
                url: '@Url.Content("/Manage/Role/SaveForm")',
                type: "post",
                data: $('form').formSerialize(),
                success: function (obj) {
                    if (obj.success) {
                        frame.msgSuccess(obj.message);
                        parent.searchGrid();
                        frame.closeDialog();
                    }
                    else {
                        frame.msgError(obj.message);
                    }
                }
            });
        }
    }
</script>